/* 引入依赖 */
const express = require("express");
const multer = require("multer");

/* 引入路由 */
const indexRouter = require("./views/indexRouter");
const userRouter = require("./views/userRouter");
const fileRouter = require("./views/fileRouter");

/* 引入配置项 */
const { publicPath } = require("./config");
console.log("publicPath", publicPath);

/* 创建express实例 */
const app = express();

/* 添加全局中间件 */
app.use(express.json());//json读写支持
app.use(express.urlencoded({ extended: false }));//表单支持
app.use(express.static(publicPath));//静态文件支持
app.use(multer({ dest: "/tmp/" }).array("avitar"));//上传支持

/* 添加路由中间件 */
app.use("/", indexRouter);
app.use("/user", userRouter);
app.use("/file", fileRouter);

/* 定义路由接口 */
// app.get("/", function (req, res) {
//     res.send("Hello Express");
// });

/* 挂载到指定端口 */
const server = app.listen(8002, function () {
    const host = server.address().address;
    const port = server.address().port;
    console.log("应用实例，访问地址为 http://%s:%s", host, port);
});
